<?php

$root = dirname(__FILE__);
define('BASEPATH',$root.'/');
require_once $root.'/config.php';
require_once $root.'/phpmailer/class.phpmailer.php';

if(!file_exists($logFile)){
  exit("No log !\n");
}
//壓縮log文件
$cmd = sprintf('/bin/tar -czf %s.tar.gz %s',$logFile,$logFile);
$status = @system($cmd);

$logTar = $logFile;
if(!$status){
  $logTar = $logFile.'.tar.gz';
}

$mail = new PHPMailer();

$mail->IsSMTP();					// 启用SMTP
$mail->Host = "smtp.gmail.com";			        //SMTP服务器
$mail->SMTPSecure = "ssl";
$mail->Port = 465;//465 ssl
$mail->Timeout = 300;//5min
$mail->SMTPAuth = true;					//开启SMTP认证
$mail->Username = "apenvideo@gmail.com";		// SMTP用户名
$mail->Password = "iloveAPEN";				// SMTP密码

$mail->From = "apenvideo@gmail.com";			//发件人地址
$mail->FromName = "AutoPostVideo";			//发件人
$mail->AddAddress("apenjav@gmail.com", "Apenjav");	//添加收件人
$mail->AddReplyTo("apenvideo@gmail.com", "AutoPostVideo");	//回复地址
$mail->WordWrap = 50; 				        //设置每行字符长度

$mail->AddAttachment($logtar);		// 添加附件
/** 附件设置
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");	// 添加附件,并指定名称
*/

$mail->IsHTML(true);					// 是否HTML格式邮件
$mail->CharSet = "utf-8";				// 这里指定字符集！
$mail->Encoding = "base64"; 

$mail->Subject = sprintf("[apen] %s 錯誤記錄",date('Y-m-d'));			//邮件主题
$mail->Body    = "影片番號，是否有圖片信息，影片是否上傳成功!</b>";		//邮件内容
$mail->AltBody = "影片番號，是否有圖片信息，影片是否上傳成功";	//邮件正文不支持HTML的备用显示

//$mail->SMTPDebug = true;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

@unlink($logtar);
@unlink($logfile);

